#include <stdio.h>
#include <stdlib.h>

int main()
{
    char a[110];
    int b[110]={0};
    while(scanf("%s",a)!=EOF)
    {
        int i=0,min=9999;
        while(a[i]!='\0')
        {
            if(a[i]=='2'||a[i]=='0'||a[i]=='1'||a[i]=='6')
            {
                b[a[i]]++;
            }
            i++;
        }
        if(b['2']==0||b['0']==0||b['1']==0||b['6']==0)
        {
            min=0;
        }
        else
        {
            if(b['2']<min)
                    min=b['2'];
           if(b['0']<min)
                    min=b['0'];
            if(b['1']<min)
                    min=b['1'];
            if(b['6']<min)
                    min=b['6'];
        }
        printf("%d\n",min);
    }
    return 0;
}
